package org.example.auth.service;

import org.example.common.core.domain.model.LoginSocial;
import org.example.common.core.domain.model.LoginSocialConfig;
import org.example.common.core.domain.model.LoginUser;
import org.example.common.core.exception.ServiceException;
import org.example.common.core.utils.SpringUtils;

import java.util.Map;

public interface IAuthUserStrategy {


    public static String BASE_NAME="AuthUserStrategy";

    /**
     * 通过用户账号获取用户
     * @param grantUser
     * @param tenantId
     * @param username
     * @return
     */
    static LoginUser getLoginUserByUsername(String grantUser,String tenantId,String username){
        // 授权类型和客户端id
        String beanName = grantUser + BASE_NAME;
        if (!SpringUtils.containsBean(beanName)) {
            throw new ServiceException("授权类型不正确!");
        }
        IAuthUserStrategy instance = SpringUtils.getBean(beanName);
        return instance.getLoginUserByUsername(tenantId,username);
    }
    /**
     * 通过用户账号获取用户
     * @param tenantId
     * @param username
     * @return
     */
    LoginUser getLoginUserByUsername(String tenantId,String  username);


    /**
     * 通过用户ID获取用户
     * @param grantUser
     * @param tenantId
     * @param userId
     * @return
     */
    static LoginUser getLoginUserByUserId(String grantUser,String tenantId,Long userId){
        // 授权类型和客户端id
        String beanName = grantUser+ BASE_NAME;
        if (!SpringUtils.containsBean(beanName)) {
            throw new ServiceException("授权类型不正确!");
        }
        IAuthUserStrategy instance = SpringUtils.getBean(beanName);
        return instance.getLoginUserByUserId(tenantId,userId);
    }

    /**
     * 通过用户ID获取用户
     * @param tenantId
     * @param userId
     * @return
     */
    LoginUser getLoginUserByUserId(String tenantId,Long  userId);


    /**
     * 获取第三方授权绑定信息
     * @param grantUser
     * @param tenantId
     * @param authId
     * @return
     */
    static LoginSocial getLoginSocialByAuthId(String grantUser, String tenantId, String authId){
        // 授权类型和客户端id
        String beanName = grantUser+ BASE_NAME;
        if (!SpringUtils.containsBean(beanName)) {
            throw new ServiceException("授权类型不正确!");
        }
        IAuthUserStrategy instance = SpringUtils.getBean(beanName);
        return instance.getLoginSocialByAuthId(tenantId,authId);
    }
    /**
     * 获取第三方授权绑定信息
     * @param tenantId
     * @param authId
     * @return
     */
    LoginSocial getLoginSocialByAuthId(String tenantId,String  authId);


    /**
     * 获取租户下对应第三方登录配置
     * @param grantUser
     * @param tenantId
     * @return
     */
    static Map<String, LoginSocialConfig> getLoginSocialConfig(String grantUser, String tenantId){
        // 授权类型和客户端id
        String beanName = grantUser+ BASE_NAME;
        if (!SpringUtils.containsBean(beanName)) {
            throw new ServiceException("授权类型不正确!");
        }
        IAuthUserStrategy instance = SpringUtils.getBean(beanName);
        return instance.getLoginSocialConfig(tenantId);
    }

    /**
     * 获取租户下对应第三方登录配置
     * @param tenantId
     * @return
     */
    Map<String, LoginSocialConfig> getLoginSocialConfig(String tenantId);



    /**
     * 通过用户手机号获取用户
     * @param grantUser
     * @param tenantId
     * @param phone
     * @return
     */
    static LoginUser getLoginUserByPhone(String grantUser,String tenantId,String phone){
        // 授权类型和客户端id
        String beanName = grantUser + BASE_NAME;
        if (!SpringUtils.containsBean(beanName)) {
            throw new ServiceException("授权类型不正确!");
        }
        IAuthUserStrategy instance = SpringUtils.getBean(beanName);
        return instance.getLoginUserByPhone(tenantId,phone);
    }
    /**
     * 通过用户账号获取用户
     * @param tenantId
     * @param phone
     * @return
     */
    LoginUser getLoginUserByPhone(String tenantId,String  phone);


    /**
     * 通过用户手机号获取用户
     * @param grantUser
     * @param tenantId
     * @param email
     * @return
     */
    static LoginUser getLoginUserByEmail(String grantUser,String tenantId,String email){
        // 授权类型和客户端id
        String beanName = grantUser + BASE_NAME;
        if (!SpringUtils.containsBean(beanName)) {
            throw new ServiceException("授权类型不正确!");
        }
        IAuthUserStrategy instance = SpringUtils.getBean(beanName);
        return instance.getLoginUserByEmail(tenantId,email);
    }
    /**
     * 通过用户账号获取用户
     * @param tenantId
     * @param email
     * @return
     */
    LoginUser getLoginUserByEmail(String tenantId,String  email);



}
